package cn.tedu.file;
/**
 * @Author 金帮嘉诚  @Date 2021-06-17 周四 16:21
 */
/*本类用于测试字符输出流*/

import java.io.*;

/**
 * 知识点：
 * Writer()
 * FileWriter() 第二个参数设置为true追加数据
 * BufferedWriter()
 */
public class TestOut2 {
    public static void main(String[] args) {
        method1();
        method2();
    }

    private static void method2() {
        Writer out = null;

        try {
//            out=new BufferedWriter(new FileWriter(new File("D:\\ready\\3.txt")));
            out = new BufferedWriter(new FileWriter("D:\\ready\\3.txt", true));//可以追加


//            out.write(98);
//            out.write(98);
//            out.write(98);
//            out.write(98);
//            out.write(98);
            out.write("11111111111111");
            out.write("金帮嘉诚哥哥你好帅啊");
            out.write("金帮嘉诚哥哥你好帅啊");
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method1() {
        Writer out = null;

        try {
//        out =new FileWriter(new File("D:\\ready\\3.txt"));
            out = new FileWriter("D:\\ready\\3.txt", true);//可以追加

//            out.write(99);
//            out.write(99);
//            out.write(99);
//            out.write(99);
//            out.write(99);
            out.write("Hello");
            out.write("Hello");
            out.write("Hello");
            out.write("Hello");

        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
